<template>
  <div class="app-container">
    <div class="ProductionDynamic">
      <!-- 头部 -->
      <div class="ProductionDynamicHeader">
        <Find :OriginalFilter="{ static: true }" :formList="formList" @findClicked="findClicked" />
      </div>
      <el-card shadow="never" :body-style="{ padding: '10px 10px 0' }" class="mt10">
        <div slot="header" class="f16">
          <span style="font-weight: 600">生成生产动态表</span>
        </div>
        <div class="mt10">
          <span class="mr10">日期</span>
          <el-input placeholder="" class="MainRightMainPoInput mr24" />
          <span class="mr10">核算时间</span>
          <el-input placeholder="" class="MainRightMainPoInput mr24" />
          <el-button class="primaryBth" type="primary" size="small">生成生产动态表</el-button>
        </div>
      </el-card>

      <el-card shadow="never" :body-style="{ padding: '10px' }">
        <div slot="header" class="f16">
          <span style="font-weight: 600">生产动态查询</span>
        </div>
        <Table
          :tableHeader="tableHeader"
          :tableData="tableData"
          class="mt10"
          :TableHeight="100"
          :outTableHeight="150"
          :summaryData="summaryData"
          summary
          @currentRow="currentRow"
          :isLoading="isLoading"
        />
        <PageModule :PageData="{ total }" @pageSizeChange="handleSizeChange" @pageChange="handleCurrentChange" />
      </el-card>
    </div>

    <el-drawer :direction="'ttb'" v-model="drawer" :with-header="false">
      <span>Hi there!</span>
    </el-drawer>
  </div>
</template>
<script lang="ts">
import { defineComponent, onMounted, ref, watch } from 'vue'
import JMessage from '@/utils/JMessage'
export default defineComponent({
  name: 'ProductionDynamicAnalysisKa'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
import Find from '@/components/Find/index.vue'
import service from '@/utils/request'
import { ElMessage } from 'element-plus'
const drawer = ref(false)
const formList = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入指令',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入型体',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入颜色',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入客户',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入客人货号',
    inputValue: ''
  },
  {
    type: 'date',
    dateLabel: '交期',
    dateValue: ''
  },

  {
    type: 'date',
    dateLabel: '下单日期',
    dateValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '线别',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '季度',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'checkbox',
    checkboxLabel: '未结束',
    checked: true
  },
  {
    type: 'checkbox',
    checkboxLabel: '已结束',
    checked: true
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '导出生产动态条'
  },
  {
    type: 'button',
    checkboxLabel: '导出生产周期表'
  },
  {
    type: 'button',
    checkboxLabel: '时程内栏定义'
  }
])

const tableData = ref([])

const tableHeader = ref([
  {
    fixed: true,
    label: '客户',
    prop: 'custom',
    width: '76px'
  },
  {
    fixed: true,
    label: '指令',
    prop: 'lotNo',
    width: '76px'
  },
  {
    fixed: true,
    label: '型体',
    prop: 'style',
    width: '76px'
  },
  {
    fixed: true,
    label: '配色',
    prop: 'color',
    width: '58px'
  },
  {
    fixed: true,
    label: '订单量',
    prop: 'orderQty',
    width: '58px'
  },
  {
    fixed: true,
    label: '预补单',
    prop: 'surplusQty',
    width: '58px'
  },
  {
    fixed: true,
    label: '下单日期',
    prop: 'orderDate',
    width: '58px'
  },
  {
    fixed: true,
    label: '客户交期',
    prop: 'deliveryDate',
    width: '58px'
  },
  {
    fixed: true,
    Multistage: true,
    label: '斩刀试作',
    children: [
      {
        label: '计划日期',
        prop: 'purPlanDate'
      },
      {
        label: '实际日期',
        prop: 'purActualDate'
      }
    ]
  },
  {
    fixed: true,
    label: '欠料',
    prop: 'schQty',
    width: '58px'
  },
  {
    fixed: true,
    Multistage: true,
    label: '主面料',
    children: [
      {
        label: '计划日期',
        prop: 'whPlanDate'
      },
      {
        label: '实际日期',
        prop: 'whActualDate'
      }
    ]
  },
  {
    Multistage: true,
    label: '冲裁',
    children: [
      {
        label: '冲裁组别',
        prop: 'cutDept',
        width: '58px'
      },
      {
        label: '裁断当日',
        prop: 'cutProd',
        width: '58px'
      },
      {
        label: '裁断欠数',
        prop: 'cutShort',
        width: '58px'
      },
      {
        label: '计划完成',
        prop: 'cutPlanDate',
        width: '58px'
      },
      {
        label: '实际完成',
        prop: 'cutActualDate',
        width: '58px'
      }
    ]
  },
  {
    Multistage: true,
    label: '工艺',
    children: [
      {
        label: '工艺欠数',
        prop: 'hfShort',
        width: '58px'
      },
      {
        label: '计划完成',
        prop: 'hfPlanDate',
        width: '58px'
      },
      {
        label: '实际完成',
        prop: 'hfActualDate',
        width: '58px'
      }
    ]
  },
  {
    Multistage: true,
    label: '配套',
    children: [
      {
        label: '配套当日',
        prop: 'partProd',
        width: '58px'
      },
      {
        label: '配套欠数',
        prop: 'partShort',
        width: '58px'
      },
      {
        label: '计划完成',
        prop: 'partPlanDate',
        width: '58px'
      },
      {
        label: '实际完成',
        prop: 'partActualDate',
        width: '58px'
      }
    ]
  },
  {
    Multistage: true,
    label: '针车',
    children: [
      {
        label: '针车组别',
        prop: 'stitchDept',
        width: '58px'
      },
      {
        label: '当日产量',
        prop: 'stitchProd',
        width: '58px'
      },
      {
        label: '针车欠数',
        prop: 'stitchShort',
        width: '58px'
      },
      {
        label: '计划完成',
        prop: 'stitchPlanDate',
        width: '58px'
      },
      {
        label: '实际完成',
        prop: 'stitchActualDate',
        width: '58px'
      }
    ]
  },
  {
    Multistage: true,
    label: '鞋面仓',
    children: [
      {
        label: '库存',
        prop: 'upperStock'
      }
    ]
  },
  {
    Multistage: true,
    label: '大底',
    children: [
      {
        label: '大底厂商',
        prop: 'soleDept'
      },
      {
        label: '当日入库',
        prop: 'soleProd'
      },
      {
        label: '欠数',
        prop: 'soleShort'
      },
      {
        label: '计划完成',
        prop: 'solePlanDate'
      },
      {
        label: '实际完成',
        prop: 'soleActualDate'
      }
    ]
  },
  {
    Multistage: true,
    label: '鞋垫',
    children: [
      {
        label: '欠数',
        prop: 'soleShort2'
      }
    ]
  },
  {
    Multistage: true,
    label: '成型投料',
    children: [
      {
        label: '成型组别',
        prop: 'lastDept'
      },
      {
        label: '当日投料',
        prop: 'lastProd'
      },
      {
        label: '投料欠数',
        prop: 'lastShort'
      },
      {
        label: '计划完成',
        prop: 'lastPlanDate'
      },
      {
        label: '实际完成',
        prop: 'lastActualDate'
      }
    ]
  },
  {
    Multistage: true,
    label: '成型产出',
    children: [
      {
        label: '当日产出',
        prop: 'finishProd'
      },
      {
        label: '欠数',
        prop: 'finishShort'
      },
      {
        label: '计划完成',
        prop: 'finishPlanDate'
      },
      {
        label: '实际完成',
        prop: 'finishActualDate'
      }
    ]
  }
])
// 表一模块
// '置空'按钮
const findClicked = (content: string) => {
  if (content === '置空') {
    formList.value.forEach((item) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
  }
  getTableList()
}
const imgList = ref([])
// 总计
interface summaryDataType {
  index: number
  num: number | undefined
}
const summaryData = ref<summaryDataType[]>([
  {
    index: 4,
    num: 0
  },
  {
    index: 5,
    num: 0
  },
  {
    index: 14,
    num: 0
  },
  {
    index: 21,
    num: 0
  },
  {
    index: 22,
    num: 0
  },
  {
    index: 30,
    num: 0
  },
  {
    index: 38,
    num: 0
  },
  {
    index: 42,
    num: 0
  }
])
// 分页器
const currentPage = ref(1)
const pageSize = ref(40)
const total = ref(0)
const handleSizeChange = (val: number) => {
  pageSize.value = val
  getTableList()
}
const handleCurrentChange = (val: number) => {
  currentPage.value = val
  getTableList()
}
// 表格计算函数
const cfmFlag = () => {
  const Unaudited = formList.value.find((item: any) => item.type === 'checkbox' && i18n.global.t(item.checkboxLabel) === '未结束')
  const Audited = formList.value.find((item: any) => item.type === 'checkbox' && i18n.global.t(item.checkboxLabel) === '已结束')
  if (!Unaudited || !Audited) return
  if (Unaudited.checked && Audited.checked) {
    return ''
  } else if (Unaudited.checked) {
    return 'N'
  } else if (Audited.checked) {
    return 'Y'
  } else {
    ElMessage('必须至少选择一项')
    Unaudited.checked = true
    Audited.checked = true
    return ''
  }
}
const isLoading = ref(true)

// 获取表数据
const getTableList = async () => {
  isLoading.value = true
  let tableDataList = await service.post<any, any>('/PcProdStatus2/getProductionDynamicQuery', {
    color: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入颜色'
    )?.inputValue, //	颜色
    custom: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入客户'
    )?.inputValue, //	客户
    deliveryEndDate: formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '交期'
    )?.dateValue?.[1], //	交期日期结束
    deliveryStartDate: formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '交期'
    )?.dateValue?.[0], //	交期日期开始
    flag: cfmFlag(), //	Y 已结束 N 未结束
    goods: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入客人货号'
    )?.inputValue, //	货号
    line: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '线别')
      ?.selectValue, //	线别
    lotNo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入指令'
    )?.inputValue, //	指令
    orderEndDate: formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '下单日期'
    )?.dateValue?.[1], //	下单日期结束
    orderStartDate: formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '下单日期'
    )?.dateValue?.[0], //	下单日期开始
    pageNum: currentPage.value, //
    pageSize: pageSize.value, //
    season: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '季度')
      ?.selectValue, //	季度
    style: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入型体'
    )?.inputValue //	型体
  })
  isLoading.value = false
  tableData.value = tableDataList.queryData
  total.value = tableDataList.total
  summaryData.value[0].num = tableDataList.count.orderCount
  summaryData.value[1].num = tableDataList.count.surplusCount
  summaryData.value[2].num = tableDataList.count.cutProdCount
  summaryData.value[3].num = tableDataList.count.partProdCount
  summaryData.value[4].num = tableDataList.count.partShortCount
  summaryData.value[5].num = tableDataList.count.upperStockCount
  summaryData.value[6].num = tableDataList.count.lastProdCount
  summaryData.value[7].num = tableDataList.count.finishProdCount
}
onMounted(() => {
  getTableList()
})
watch(
  () =>
    formList.value.map((item: any) => {
      item.selectValue, item.inputValue, item.dateValue, item.checked
    }),
  () => {
    getTableList()
  }
)

// 点击表给另一张表传数据
const currentRow = async (row: any) => {
  drawer.value = true
}
</script>

<style lang="less" scoped>
// 主体样式
.ProductionDynamicMain {
  width: 100%;
  height: 670px;
  margin-top: 20px;

  .ProductionDynamicMainCard {
    width: 100%;
    height: 100%;
    box-shadow: none;
  }
}

// 主体
.ProductionDynamicMainCardHeader {
  width: 98%;
  height: 60px;
  margin: auto;
  margin-top: 10px;
}

.ProductionDynamicMainCardMain {
  width: 98%;
  height: 480px;
  margin-top: 10px;
  margin: auto;
  margin-bottom: 80px;
}

.ProductionDynamicMainCardBottom {
  width: 98%;
  height: 80px;
  display: flex;
  justify-content: space-between;
}

// H1字体
.ProductionDynamicMainCardHeaderH1 {
  font-size: 16px;
}

.ProductionDynamicMainCardHeaderDiv {
  width: 100%;
  height: 50px;
  display: flex;
  margin-top: 5px;
}

// Input 输入框的样式
.MainRightMainPoInput {
  width: 88px;
  height: 25px;
}

// 生产动态查询 样式
.ProductionDynamicMainCardMainTop {
  width: 100%;
  height: 40px;
  display: flex;
  justify-content: space-between;

  .ProductionDynamicMainCardMainTopRight {
    width: 80%;
    height: 100%;
  }
}

.ProductionDynamicMainCardMainBottom {
  width: 100%;
  height: 92%;
  display: flex;

  .ProductionDynamicMainCardMainBottomLeft {
    width: 50%;
    height: 100%;
  }

  .ProductionDynamicMainCardMainBottomRight {
    width: 50%;
    height: 100%;
  }
}

// 时间线
.timeline {
  display: flex;
  margin-top: 15px;

  .timeline-dot {
    width: 27px;
    height: 1px;
    background: #e7e7e7;
    border-radius: 0px 0px 0px 0px;
    opacity: 1;
    margin-top: 10px;
  }

  .timelineH1 {
    margin-left: 5px;
    margin-right: 5px;
    margin-top: 10px;
  }
}

.timeline-dotOne {
  margin-left: 193px;
}

.timeline-dotTwo {
  width: 35px !important;
  margin-left: 58px;
}

.timeline-dotThree {
  width: 96px !important;
  margin-left: 11px;
}

.timelineRight {
  width: 96px !important;
}

.timeline-dotFore {
  width: 70px !important;
  margin-left: 7px;
}

.timeline-dotFive {
  width: 66px !important;
  margin-left: 5px;
}

:deep(.ProductionDynamicMainCardBottom .el-input__wrapper) {
  background-color: #fff5eb;
}

.save {
  color: black;
  border: 1px solid #e7e7e7;
  background: #e7e7e7;
}
</style>
